package com.cf.controller;

import com.cf.constant.EnumReturnCode;
import com.cf.id.SnowflakeId;
import com.cf.model.Connection;
import com.cf.service.ConnectionService;
import com.cf.vo.ResponseVo;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * game-server-ApiConnectionController
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/6/15 下午 02:30
 */
@RestController
@RequestMapping("/api/v1.0/connection")
public class ApiConnectionController {

    @Autowired
    private SnowflakeId id;

    @Autowired
    private ConnectionService connectionService;

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST)
    public ResponseVo<Boolean> apply(@Validated @RequestBody Connection connection, BindingResult bindingResult) {
        if (bindingResult.hasFieldErrors()) {
            return ResponseVo.fail(EnumReturnCode.ERROR.getCode(), null, "参数数据缺失！");
        }
        connection.setId(id.nextId());
        connectionService.insert(connection);
        return ResponseVo.success(null, "信息提交成功，请等待客服联系");
    }

}
